﻿// See https://aka.ms/new-console-template for more information

using MongoDB.Bson;
using MongoDB.Driver;

Console.WriteLine("Hello, World!");

var client = new MongoClient("mongodb://localhost:37017");
var database = client.GetDatabase("DemoDatabase");
var collection = database.GetCollection<BsonDocument>("DemoCollection");

var document1 = new BsonDocument {
    ["title"] = "title 1", ["author"] = "author 1", ["content"] = "content 1"
};

collection.InsertOne(document1);

var document2 = new BsonDocument {
    ["title"] = "title 1", ["source"] = "http://no.such.url", ["md5"] = "xxxx"
};

collection.InsertOne(document2);

var cursor = collection.FindSync(
    new BsonDocumentFilterDefinition<BsonDocument>(
        new BsonDocument { ["author"] = "author 1" }));
Console.WriteLine(cursor.First()["title"].AsString);